package com.algorithm.ch1.yjx.array;

/**
 * @author yuanjianxin
 * @date 2018/8/13 11:07
 */
public class MaxProfit {
    public static void main(String[] args) {
        int[] prices = {7, 6, 4, 3, 1};
        System.out.println(maxProfit(prices));
    }

    public static int maxProfit(int[] prices) {
        int total = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            int diff = prices[i + 1] - prices[i];
            if (diff > 0) {
                total += diff;
            }
        }
        return total;
    }
}
